//
//  AllGoodsViewController.m
//  GLGW_Shoping
//
//  Created by yang on 2018/11/9.
//  Copyright © 2018年 yang. All rights reserved.
//

#import "AllGoodsViewController.h"
#import "StoreAllGoodsListViewModel.h"
#import "GoodsInformationViewController.h"
#import "StroeAllGoodsModel.h"

@interface AllGoodsViewController ()<AllGoodsInfoeDelegate>{
    StroeAllGoodsModel * stroeGoodsModel;
}
@property (nonatomic,strong) StoreAllGoodsListViewModel * allViewModel;
@end

@implementation AllGoodsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.navigationController.navigationBar setBackgroundImage:[[UIImage imageWithColor:[UIColor colorWithHexString:@"#F2F2F2"]]init]
                                                  forBarMetrics:UIBarMetricsDefault];
    self.allViewModel = [[StoreAllGoodsListViewModel alloc] initWithViewToViewModel:self.tableView theSuperView:self.view];
    self.allViewModel.delegate = self;
    [self headerRereshing];
}

-(void)headerRereshing{
    self.page = 1;
    [self loadData];
}

-(void)footerRereshing{
    if (self.page < stroeGoodsModel.data.pages) {
        self.page ++;
        [self loadData];
    }else{
        [GLGWProgressHUD showNotice:@"没有更多店铺信息了！" view:nil];
        [self.tableView.mj_footer endRefreshing];
        [self.tableView.mj_header endRefreshing];
    }
}

-(void)loadData{
    NSDictionary * parDic = @{@"categoryId":@"",
                              @"productIds":@"",
                              @"specificationsIds":@"",
                              @"materialIds":@"",
                              @"factoryIds":@"",
                              @"tradingMode":@"",
                              @"priceFlag":@"",
                              @"timeFlag":@"",
                              @"cityCode":@"",
                              @"shopId":@(self.storeId),//3有数据
                              @"page":@(self.page),
                              @"pageSize":@15};
    @weakify(self)
    [[self.allViewModel.goods_recommendCommand execute:parDic]subscribeNext:^(id x) {
        @strongify(self)
        self->stroeGoodsModel = (StroeAllGoodsModel *)x;
        [self.tableView.mj_footer endRefreshing];
        [self.tableView.mj_header endRefreshing];
    }error:^(NSError *error) {
        [self.tableView.mj_footer endRefreshing];
        [self.tableView.mj_header endRefreshing];
        
    }];
}



#pragma mark  -- AllGoodsInfoeDelegate
-(void)chickSelectRow:(NSInteger)s_row{
    GoodsInformationViewController * goodsInforVC = [GoodsInformationViewController new];
    [self.navigationController pushViewController:goodsInforVC animated:YES];
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
